/**
 * Created by will on 2017/10/18.
 */
/**
 * Created by will on 2017/9/28.
 */
$(function () {
    layui.use(['form', 'laypage', 'laydate','table','layer'], function(){
        var form = layui.form,
            laypage=layui.laypage
            ,laydate=layui.laydate
            ,table=layui.table
            ,layer=layui.layer;
        //全选
        form.on('checkbox(allchoose)', function(data){
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function(index, item){
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
        table.on('checkbox(test)', function(obj){
            console.log(obj.checked); //当前是否选中状态
            console.log(obj.data); //选中行的相关数据
            console.log(obj.type); //如果触发的是全选，则为：all，如果触发的是单选，则为：one
        });
        laypage.render({
            elem: 'paid-paging'
            , count: 100
            , theme: '#45A2FF'
            , groups: 4
            ,prev: '<em><</em>'
            ,next: '<em>></em>'
            , layout: ['prev', 'page', 'next', 'limit', 'skip']
            , jump: function (obj) {
                console.log(obj)
            }
        });
        //日期控件
        laydate.render({
            elem: '#date1'
            ,type:'datetime'
            ,theme: '#45a2ff'
        });
        laydate.render({
            elem: '#date2'
            ,type:'datetime'
            ,theme: '#45a2ff'
        });
        laydate.render({
            elem: '#date3'
            ,type:'datetime'
            ,theme: '#45a2ff'
        });
        laydate.render({
            elem: '#date4'
            ,type:'datetime'
            ,theme: '#45a2ff'
        });
        laydate.render({
            elem: '#paid-window-date'
            ,type:'datetime'
            ,theme: '#45a2ff'
        });
        //    结算按钮弹出层
        //触发事件
        var active = {
            offset: function(othis){
                var type = othis.data('type')
                    ,text = othis.text();

                layer.open({
                    type: 1
                    ,title:false
                    ,offset: type //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                    ,id: 'layerDemo'+type //防止重复弹出
                    ,area:["560px","753px"]
                    ,content: $('.easytrip-paid-window')
                    ,btn: ['结算', '取消']
                    ,closeBtn: false
                    ,btnAlign: 'c' //按钮居中
                    ,shade: 0.8 //不显示遮罩
                    ,yes: function(){
                        layer.closeAll();
                    }
                });
            }
        };

        $('.settlement-btn .layui-btn').on('click', function(){
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });
    })
//    全选功能
    $("#selectAll").click(function () {
        alert  (1);
        if(this.checked){
            $("#select-list :checkbox").prop("checked", true);
        }else{
            $("#select-list :checkbox").prop("checked", false);
        }
    })
})